<?php
/**
 * 获取用户信息
 * User: lxq
 * Date: 2018/5/21
 * Time: 10:07
 */
class memberControl extends Control {

    public function __construct()
    {
        parent::__construct();
    }

    public function shop_memberOp()
    {
        $member_model = Model('member');
        $phone = isset($_GET['phone'])?$_GET['phone']:$_POST['phone'];
        $member_info = $member_model->getMemberInfo(array('mobile'=>$phone));
        $check = $this->check_merchant($phone);//查询该用户是否是后台添加的商家
        if(!empty($member_info)){
            if($check){
                $this->response(array('is_merchant'=>1),2000,'商城用户信息');
            }else{
                $this->response(array('is_merchant'=>0),2000,'商城用户信息');
            }
        }else{
            //新增用户 将用户写入数据库
            $user_info = array();
            $user_info['mobile'] = $phone;
            $user_info['addtime'] = time();
            $is_merchant = 0;
            if($check){
                $user_info['is_merchant']=1;
                $user_info['merchant_id']= $check['merchant_id'];
                $is_merchant = 1;
            }
            $member_id = $member_model->addMember($user_info);
            if($member_id){
                $this->response(array('is_merchant'=>$is_merchant),2000,'商城用户信息');
            }
        }
    }


    /**
     * 查询该手机号是否是商家
     */
    public function check_merchant($mobile)
    {
        /** @var member_merchantModel $merchant_model */
        $merchant_model = Model('member_merchant');
        $merchant_info = $merchant_model->getMerchantInfo(array('mc_phone'=>$mobile));
        if($merchant_info && is_array($merchant_info)){
            return $merchant_info;
        }else{
            return false;
        }
    }
}